<?php
/*
 * @Date: 2023-03-23 11:48:02
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2023-04-04 10:58:26
 * @FilePath: \php-framework\tp6\app\api\model\SupplyOrder.php
 */

declare(strict_types=1);

namespace app\api\model;

use app\common\model\TimeModel;
use app\wx\model\SystemAdmin;
use EasyWeChat\Factory;
use NieGe\Redis;
use think\facade\Env;

class SupplyOrder extends TimeModel
{
    public static function supplyor($touser,$wxapp)
    {
            $config = [
                'app_id' => Env::get('wx.appid'),
                'secret' => Env::get('wx.appsecret'),
                'token' => Env::get('wx.token'),
                'response_type' => 'array',
            ];
            // 使用配置来初始化一个公众号应用实例。
            $app = Factory::officialAccount($config);

                //向指定用户发送模板消息
                $app->template_message->send([
                    "touser" => "$touser",
                    "template_id" => "Nay-T2Q0v8o2lWZS2lFz1irubrde579RooNum4ZZmbs",
                    'url' => 'http://www.jsadmin.com/admin/index',
                    'data' => [
                        "name" => [
                            "value" => $wxapp["name"],
                            "color" => "#0000FF"
                        ],
                        "status" => [
                            "value" => $wxapp["status"],
                            "color" => "#0000FF"
                        ]
                    ],
                ]);
                $response = $app->server->serve();
                $response->send();
                return $response; 
    }
}
